<template>
	<view>
		<view class="shujuList">
			<view class="shujuItem">
				<view class="goodsInfo">
					<view class="leftInfo">
						<image :src="detail.product.image[0].file_path" mode="aspectFit"></image>
					</view>
					<view class="rightInfo">
						<view class="" style="display: flex;font-weight: 800;font-size: 30rpx;">
							<view class="goodsName">
								{{detail.product.product_name }}
							</view>
							<view class="goodsPrice">
								￥{{ detail.total_rent }}
							</view>
						</view>
						<view class="" style="display: flex;">
							<view class="">
								已选：{{ detail.product_attr }} + {{ detail.lease_time }} 天
							</view>
							<view class="" style="width: 100rpx;">
								x 1
							</view>
						</view>
					</view>

				</view>
				<view class="twoBtnBox">
					<!-- 			<button v-if="!token" class="submitBtn" @getAuthorize="onGetAuthorize1" open-type="getAuthorize"
						scope="phoneNumber" onError="handleAuthError">确认订单
					</button> -->
					<view class="submitBtn" @click="gotoshopDetail">
						确认订单
					</view>
					<view class="callBtn" @click="call">
						联系商家
					</view>
				</view>
			</view>
			<u-popup :show="showLogin" round="16rpx" mode="center" :safeAreaInsetBottom="false" closeColor="#fff"
				@close="showLogin = false" closeable closeIconPos="bottom-center">
				<view class="d-c-c d-c" style="padding: 30rpx;">
					<view class="fb" style="font-size: 36rpx">请先登录~</view>
					<button class=""
						style="color: #fff; margin-top: 20rpx; border-radius: 80rpx; width: 400rpx; height: 80rpx; text-align: center; line-height: 80rpx; background: #5BC5BB;"
						@getAuthorize="onGetAuthorize" open-type="getAuthorize" scope="phoneNumber"
						onError="handleAuthError">
						授权手机号一键登录
					</button>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order_id: '',
				order_product_id: '',
				detail: {},
				token: '',
				product_num: 1,
				showLogin:false
			}
		},
		onLoad(options) {
			console.log(options, '=---options--');

			console.log(options.order_product_id, '----');
			// this.order_product_id = uni.getStorageSync('order_product_id')
			// if(!this.order_product_id){
			// 	const options1 = my.getEnterOptionsSync();
			// 	this.order_product_id = options1.query.order_product_id
			// }
			this.order_product_id = options.order_product_id
			console.log(options.order_product_id, '----');
			//正式
			this.token = uni.getStorageSync('token')
			// this.order_product_id = 3  //测试  
			this.getdata()
		},
		methods: {
			getdata() {
				let self = this
				self._post('order.fast_order/detail', {
					order_product_id: self.order_product_id,
					app_id: 10001
				}, function(res) {
					self.detail = res.data
					self.order_id = res.data.order_product_id
					self.product_id = res.data.order_product_id
				});
			},
			gotoshopDetail() {
				let self = this
				console.log(self.getLoginStatus(), 'self.getLoginStatus()')
				if (self.getLoginStatus()) {
					let zhouqi = (this.detail.lease_time / 30)
					uni.navigateTo({
						url: "/pages/order/confirm-order?product_id=" + self.product_id + '&product_num=' + self
							.product_num +
							'&product_sku_id=' + '' + '&order_type=buy' + '&zmshow=' + 1 + '&zhouqi=' + zhouqi +
							'&fastOrder=' + 1
					})
				} else {
					self.showLogin = true
				}
			},
			// 支付宝登录
			async onGetAuthorize() {
				let self = this
				console.log(1111)
				my.getAuthCode({
					scopes: ['auth_base'],
					success: (res) => {
						my.getPhoneNumber({
							success: (res1) => {
								let encryptedData = res1.response;
								encryptedData = JSON.parse(encryptedData);
								let response = encryptedData.response
								this._post('user.usermp/mnpAlipayAuthLogin', {
									code: res.authCode,
									content: response
								}, ({
									data: {
										data
									}
								}) => {
									uni.setStorageSync('token', data.token);
									uni.setStorageSync('user_id', data.user_id);
									uni.showToast({
										title: '登录成功'
									});
									let zhouqi = (this.detail.lease_time / 30)
									uni.navigateTo({
										url: "/pages/order/confirm-order?product_id=" +
											self.product_id + '&product_num=' +
											self.product_num +
											'&product_sku_id=' + '' +
											'&order_type=buy' + '&zmshow=' +
											1 + '&zhouqi=' + zhouqi +
											'&fastOrder=' + 1
									})
								})
							}
						});
					},
					fail: err => {
					        console.log('my.getAuthCode 调用失败', err)
					      }
				});
				// my.getAuthCode({
				// 	scopes: ['auth_base'],
				// 	success: (res) => {
				// 		my.getPhoneNumber({
				// 			success: (res1) => {
				// 				let encryptedData = res1.response;
				// 				encryptedData = JSON.parse(encryptedData);
				// 				let response = encryptedData.response
				// 				self._post('user.usermp/mnpAlipayAuthLogin', {
				// 					code: res.authCode,
				// 					content: response,
				// 					tguser_id: tguser_id
				// 				}, res => {
				// 					if (res.data.code == 0) {
				// 						uni.showToast({
				// 							title: res.data.msg
				// 						});
				// 					} else {
				// 						uni.setStorageSync('token', res.data.data
				// 							.token);
				// 						uni.setStorageSync('user_id', res.data.data
				// 							.user_id);
				// 						uni.showToast({
				// 							title: '登录成功'
				// 						});
				// 						let zhouqi = (this.detail.lease_time / 30)
				// 						uni.navigateTo({
				// 							url: "/pages/order/confirm-order?product_id=" +
				// 								self.product_id + '&product_num=' +
				// 								self.product_num +
				// 								'&product_sku_id=' + '' +
				// 								'&order_type=buy' + '&zmshow=' +
				// 								1 + '&zhouqi=' + zhouqi +
				// 								'&fastOrder=' + 1
				// 						})
				// 					}

				// 				})
				// 			},
				// 			fail: (res) => {
				// 				console.log("失败")
				// 				reject(res);
				// 			}
				// 		});
				// 	},
				// });














				// my.getAuthCode({
				// 	scopes: ['auth_base'],
				// 	success: (res) => {
				// 		my.getPhoneNumber({
				// 			success: (res1) => {
				// 				let encryptedData = res1.response;
				// 				encryptedData = JSON.parse(encryptedData);
				// 				let response = encryptedData.response
				// 				self._post('user.usermp/mnpAlipayAuthLogin', {
				// 					code: res.authCode,
				// 					content: response
				// 				}, res => {
				// 					uni.setStorageSync('token', res.data.data.token);
				// 					uni.setStorageSync('user_id', res.data.data
				// 						.user_id);
				// 					uni.showToast({
				// 						title: '登录成功'
				// 					});
				// 					let zhouqi = (this.detail.lease_time / 30)
				// 					uni.navigateTo({
				// 						url: "/pages/order/confirm-order?product_id=" +
				// 							self.product_id + '&product_num=' +
				// 							self.product_num +
				// 							'&product_sku_id=' + '' +
				// 							'&order_type=buy' + '&zmshow=' +
				// 							1 + '&zhouqi=' + zhouqi +
				// 							'&fastOrder=' + 1
				// 					})
				// 				})
				// 			},
				// 			fail: (res) => {
				// 				console.log("失败")
				// 				reject(res);
				// 			}
				// 		});
				// 	},
				// });
			},
			call() {
				let self = this
				self._post('setting.setting/cyphone', {}, function(res) {
					uni.makePhoneCall({
						phoneNumber: res.data.cyphone.cyphone
					});
				});

			},

		}
	}
</script>

<style lang="scss">
	.shujuItem {
		width: 90%;
		height: 380rpx;
		background-color: #fffffF;
		margin: 20rpx auto;
		padding: 10rpx;
	}

	.shopInfo {
		display: flex;
		align-items: center;
	}

	.image1 {
		width: 50rpx;
		height: 50rpx;
	}

	.image1 image {
		width: 100%;
		height: 100%;
	}

	.image2 {
		width: 30rpx;
		height: 30rpx;
	}

	.image2 image {
		width: 100%;
		height: 100%;
	}

	.goodsInfo {
		display: flex;
		margin-top: 20rpx;
	}

	.leftInfo {
		width: 200rpx;
		height: 200rpx;
	}

	.leftInfo image {
		width: 100%;
		height: 100%;
	}

	.rightInfo {
		flex: 1;
		margin-left: 20rpx;
	}

	.twoBtnBox {

		margin: 20rpx auto;
		width: 60%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.submitBtn {
		width: 150rpx;
		height: 55rpx;
		border-radius: 50rpx;
		background-color: #06d9f6;
		color: #fffffF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.callBtn {
		width: 150rpx;
		height: 55rpx;
		border-radius: 50rpx;
		border: 1rpx solid #06d9f6;
		color: #06d9f6;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>